#kq = 1 if x is square number;

clear kq;
copy x to i;

incr kq; #default is squre number if x < 2;

decr i;
clear i_large_than_two;
while i not 0 do;
	incr i_large_than_two;
	clear kq;
	clear i;
end;

while i_large_than_two not 0 do;
	copy x to i;
	while i not 0 do;

	    #calcualte i*i
	    
	    copy i to j;
	    copy i to k;
	    
	    clear kq;
	    #let kq = j*k;
	    while k not 0 do;
	       copy j to l;
	       while l not 0 do;
		   incr kq;
		   decr l;
	       end;
	       decr k;
	    end;
	    

	    #check kq equal x
	    incr x_is_kq;
	    
	    copy x to l;
	    copy kq to temp;

	    #check if x lt kq;
	    while kq not 0 do;
		decr x;
		decr kq;
	    end;
	    while x not 0 do; #x lt kq
		decr x_is_kq;
		clear x;
	    end;

	    #check if kq lt x
	    copy temp to kq; #restore kq;
	    copy l to x;
	    while l not 0 do;
		decr kq;
		decr l;
	    end;
	    while kq not 0 do; #kq lt than x
		decr x_is_kq;
		clear kq;
	    end;
	    
	    clear kq;
	    while x_is_kq not 0 do;
		clear kq;
		incr kq;
		clear i;
		clear x_is_kq;
	    end;

	    decr i;
	end;
	clear i_large_than_two;
end;
